Skip to content

feat(util): Add const-propagating wrapper#301

Merged
bnbajwa merged 1 commit intoreactivemarkets:masterfrom
bnbajwa:util
Oct 22, 2025
Merged

feat(util): Add const-propagating wrapper#301
bnbajwa merged 1 commit intoreactivemarkets:masterfrom
bnbajwa:util

Conversation

@bnbajwa
Copy link
Copy Markdown
Contributor

@bnbajwa bnbajwa commented Oct 21, 2025

Can be used with pointers/smart pointers/custom types

Normally, constness isn't propagated to pointer/reference/smart pointer members of a class. This wrapper allows for propagation of constness. e.g.:

class S {
   int* member;
   void f() const { *member = 5; } // compiles OK -- object pointed by `member` can be modified in const method
};

class S2 {
   propagate_const<int*> member;
   void f() const { *member = 5; } // compiler ERROR -- cannot modify object pointed by `member` in const method
};

SDB-9943

@bnbajwa bnbajwa requested a review from a team as a code owner October 21, 2025 14:47
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @bnbajwa, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a robust propagate_const utility designed to enhance const-correctness for types that encapsulate pointers or pointer-like objects. By providing a consistent interface for accessing the underlying value while correctly propagating const qualifiers, this feature simplifies the development of safe and predictable APIs for smart pointers, custom wrappers, and raw pointers, ensuring that mutability is managed appropriately across different access patterns.

Highlights

  • New propagate_const Wrapper: Introduces a propagate_const class template that wraps an object and provides get(), operator->(), and operator*() methods, ensuring const propagation to the underlying pointed type.
  • Flexible Underlying Type Detection: Implements a pointed_underlying struct with specializations for types exposing a get() method (like smart pointers), raw pointers, and references, allowing the propagate_const wrapper to correctly identify and interact with the wrapped object.
  • C++20 Pointer Concept: Adds a new C++20 concept Pointer to Concepts.hpp to identify types that are raw pointers, which is utilized by the pointed_underlying mechanism.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a propagate_const wrapper class that can be used with pointers, smart pointers, and custom types to propagate constness. It also adds a Pointer concept to Concepts.hpp. The code appears well-structured, but there are a few areas that could be improved for correctness and maintainability.

Can be used with pointers/smart pointers/custom types

SDB-9943
@bnbajwa bnbajwa merged commit bf46c49 into reactivemarkets:master Oct 22, 2025
5 checks passed
@bnbajwa bnbajwa deleted the util branch October 22, 2025 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants